<?php

if ( function_exists('register_sidebar') ){
    register_sidebar(array(
        'name' => '←左边栏',
        'before_widget' => '<div id="%1$s" class="widget %2$s">',
	    'after_widget' => "</div>\n",
	    'before_title' => '<h3 class="widgettitle">',
	    'after_title' => "</h3>\n",   
    ));
    register_sidebar(array(
        'name' => '右边栏→',
        'before_widget' => '',
	    'after_widget' => '',
	    'before_title' => '<h3 class="widgettitle">',
	    'after_title' => "</h3>\n",         
    ));
}

//WordPress 2.7使用加强的留言系统，WordPress 2.7以下版本仍旧使用原来的留言系统
add_filter( 'comments_template', 'legacy_comments' );
function legacy_comments( $file ) {
	if ( !function_exists('wp_list_comments') )
		$file = TEMPLATEPATH . '/legacy.comments.php';
	return $file;
}

function seoTitle() {
    if(is_single() || is_page()){
        $title = wp_title(' | ', false, 'right') . get_bloginfo('name');
    }
    elseif(is_search() || is_404()){
        if (is_search()){
            $title = '“' . attribute_escape(apply_filters('the_search_query', get_search_query()))
                    . '”搜索结果' . ' | ' . get_bloginfo('name');
        }
        else if(is_404()){
            $title = '未找到该内容！';
        }
    }
    else{
        $paged = (isset($_GET['paged']) && !empty($_GET['paged'])) ? ' 第'.$_GET['paged'].'页' : '';
        $title = get_bloginfo('name') . wp_title(' | ', false, 'left') . $paged;
    }
    return $title;
}

//transformCode用于把<code></code>的代码进行htmlspecialchars编码
//在下面两行前添加//可以去掉transformCode效果
add_filter('the_content', 'transformCode', 0);
add_filter('comment_text', 'transformCode', 0);
function transformCode($content){
  preg_match_all('|\s<code>(.*?)</code>\s|is', $content, $output);
  $i = count($output[1]);
  for ($n=0;$n<$i;$n++){
    $transformed = '<pre class="code"><code>' . htmlspecialchars(trim($output[1][$n]), ENT_QUOTES) . '</code></pre>';
    $content = str_replace($output[0][$n], $transformed, $content);
  }
  return $content;
}
?>